package com.swak.boot.config.metrics;

import org.springframework.boot.autoconfigure.AutoConfigureAfter;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.swak.Constants;
import com.swak.boot.booter.ApplicationBooter;
import com.swak.metrics.health.HealthRegister;

/**
 * 服务健康状况
 * 
 * @author lifeng
 */
@Configuration
@AutoConfigureAfter({ MetricsAutoConfiguration.class })
@ConditionalOnProperty(prefix = Constants.ACTUATOR_METRICS, name = "health.open", matchIfMissing = true)
public class HealthConfiguration implements ApplicationBooter {

	private HealthRegister healthRegister;

	@Bean
	public HealthRegister HealthRegister() {
		this.healthRegister = new HealthRegister();
		return this.healthRegister;
	}

	@Override
	public void onApplicationEvent(ApplicationContext context) {
		if (this.healthRegister != null) {
			this.healthRegister.start();
		}
	}
}